﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace ModelLayer.Graph
{
    [KnownType(typeof(StationNode))]
    [DataContract]
    public class Edge
    {
        [DataMember]
        public int StartNodeId { get; set; }

        [DataMember]
        public int EndNodeId { get; set; }

        [IgnoreDataMember]
        private StationNode startNode;

        public StationNode StartNode
        {
            get { return startNode; }
            set { startNode = value; if (value != null) StartNodeId = value.Id; else StartNodeId = -1; }
        }

        [IgnoreDataMember]
        private StationNode endNode;

        public StationNode EndNode
        {
            get { return endNode; }
            set { endNode = value; if (value != null) EndNodeId = value.Id; else EndNodeId = -1; }
        }

        [DataMember]
        public Dictionary<WeightType, double> Weights { get; set; }

        public Edge()
        {
            StartNodeId = -1;
            EndNodeId = -1;
        }

        public void AddWeight(WeightType type, double weight)
        {
            Weights.Add(type, weight);
        }

        public void RemoveWeight(WeightType type)
        {
            Weights.Remove(type);
        }

        public enum WeightType
        {
            DISTANCE,
            TIME,
            COST
        }
    }

    
}
